package controllers;

import java.util.List;

import models.Filme;
import models.Login;
import models.RepositorioFilme;
import play.data.Form;
import play.mvc.Controller;
import play.mvc.Result;
import views.html.login;
import dao.DAOFilme;

public class Application extends Controller {

	private static Form<Login> formLogin = new Form<Login>(Login.class);

	public static List<Filme> getRanking() {
		RepositorioFilme topranking = new RepositorioFilme(new DAOFilme());
		return topranking.getfilmeTop();

	}

	public static Result login() {
		return ok(login.render(formLogin));
	}

	public static Result autenticar() {
		Form<Login> f = formLogin.bindFromRequest();
		if (f.hasErrors()) {
			return badRequest(login.render(f));
		} else {
			session("login", f.get().login);
			return redirect(routes.Application.padrao());
		}
	}

	public static Result logout() {
		session().clear();
		return redirect(routes.Application.login());
	}

	public static Result padrao() {
		return ok(views.html.padrao.render());
	}

	public static Result noticias() {
		return ok(views.html.noticia.render());
	}
}
